package com.wetool.wechat.service;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import lombok.Data;
import lombok.Getter;

import java.io.Serializable;

/**
 * 描述：
 *
 * @author zhangjie
 * @since 1.0
 */
@Data
public class AuthMessage<T> implements Serializable {

    private static final long serialVersionUID = 2953946557905707053L;

    /**
     * 返回码
     */
    private int code;

    /**
     * 返回消息
     */
    private String message;

    /**
     * 数据
     */
    @JsonInclude(Include.NON_NULL)
    private T data;

    public AuthMessage() {
    }

    public AuthMessage(Result result) {
        code = result.getCode();
        message = result.getMessage();
    }

    public AuthMessage(Result result, String msg) {
        code = result.getCode();
        message = msg;
    }

    public AuthMessage(Result result, T data) {
        code = result.getCode();
        message = result.getMessage();
        this.data = data;
    }

    @Getter
    public enum Result {
        SUCCESS(0, "操作成功！"),
        ERROR(1, "操作失败！"),
        PARAM_ERROR(2, "请求参数格式错误！"),
        USER_EXISTED(3, "用户已存在！"),
        USER_NOT_FOUND(4, "用户不存在！"),
        WECHAT_NOT_BOUND_USER(5, "当前微信未绑定微兔帐号，请注册并绑定！");

        private final int code;

        private final String message;

        Result(int code, String message) {
            this.code = code;
            this.message = message;
        }
    }
}